package com.yiren.backstage.db.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.yiren.backstage.currency.entity.record.CarRecordPointEntity;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "CAR_RECORD_POINT_ENTITY".
*/
public class CarRecordPointEntityDao extends AbstractDao<CarRecordPointEntity, Long> {

    public static final String TABLENAME = "CAR_RECORD_POINT_ENTITY";

    /**
     * Properties of entity CarRecordPointEntity.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property RecordId = new Property(1, Long.class, "recordId", false, "RECORD_ID");
        public final static Property X = new Property(2, float.class, "x", false, "X");
        public final static Property Y = new Property(3, float.class, "y", false, "Y");
        public final static Property L = new Property(4, double.class, "l", false, "L");
        public final static Property W = new Property(5, double.class, "w", false, "W");
        public final static Property Ca = new Property(6, float.class, "ca", false, "CA");
        public final static Property Dr = new Property(7, String.class, "dr", false, "DR");
        public final static Property Dl = new Property(8, String.class, "dl", false, "DL");
        public final static Property Fy = new Property(9, String.class, "fy", false, "FY");
        public final static Property Time = new Property(10, long.class, "time", false, "TIME");
        public final static Property Dg = new Property(11, int.class, "dg", false, "DG");
        public final static Property GradeId = new Property(12, String.class, "gradeId", false, "GRADE_ID");
        public final static Property Cause = new Property(13, String.class, "cause", false, "CAUSE");
        public final static Property Score = new Property(14, int.class, "score", false, "SCORE");
        public final static Property Name = new Property(15, String.class, "name", false, "NAME");
        public final static Property Voice = new Property(16, String.class, "voice", false, "VOICE");
        public final static Property Gear = new Property(17, String.class, "gear", false, "GEAR");
        public final static Property Speed = new Property(18, int.class, "speed", false, "SPEED");
    }

    private Query<CarRecordPointEntity> carInfoRecordEntity_CarRecordPointQuery;

    public CarRecordPointEntityDao(DaoConfig config) {
        super(config);
    }
    
    public CarRecordPointEntityDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"CAR_RECORD_POINT_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"RECORD_ID\" INTEGER," + // 1: recordId
                "\"X\" REAL NOT NULL ," + // 2: x
                "\"Y\" REAL NOT NULL ," + // 3: y
                "\"L\" REAL NOT NULL ," + // 4: l
                "\"W\" REAL NOT NULL ," + // 5: w
                "\"CA\" REAL NOT NULL ," + // 6: ca
                "\"DR\" TEXT," + // 7: dr
                "\"DL\" TEXT," + // 8: dl
                "\"FY\" TEXT," + // 9: fy
                "\"TIME\" INTEGER NOT NULL ," + // 10: time
                "\"DG\" INTEGER NOT NULL ," + // 11: dg
                "\"GRADE_ID\" TEXT," + // 12: gradeId
                "\"CAUSE\" TEXT," + // 13: cause
                "\"SCORE\" INTEGER NOT NULL ," + // 14: score
                "\"NAME\" TEXT," + // 15: name
                "\"VOICE\" TEXT," + // 16: voice
                "\"GEAR\" TEXT," + // 17: gear
                "\"SPEED\" INTEGER NOT NULL );"); // 18: speed
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CAR_RECORD_POINT_ENTITY\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, CarRecordPointEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long recordId = entity.getRecordId();
        if (recordId != null) {
            stmt.bindLong(2, recordId);
        }
        stmt.bindDouble(3, entity.getX());
        stmt.bindDouble(4, entity.getY());
        stmt.bindDouble(5, entity.getL());
        stmt.bindDouble(6, entity.getW());
        stmt.bindDouble(7, entity.getCa());
 
        String dr = entity.getDr();
        if (dr != null) {
            stmt.bindString(8, dr);
        }
 
        String dl = entity.getDl();
        if (dl != null) {
            stmt.bindString(9, dl);
        }
 
        String fy = entity.getFy();
        if (fy != null) {
            stmt.bindString(10, fy);
        }
        stmt.bindLong(11, entity.getTime());
        stmt.bindLong(12, entity.getDg());
 
        String gradeId = entity.getGradeId();
        if (gradeId != null) {
            stmt.bindString(13, gradeId);
        }
 
        String cause = entity.getCause();
        if (cause != null) {
            stmt.bindString(14, cause);
        }
        stmt.bindLong(15, entity.getScore());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(16, name);
        }
 
        String voice = entity.getVoice();
        if (voice != null) {
            stmt.bindString(17, voice);
        }
 
        String gear = entity.getGear();
        if (gear != null) {
            stmt.bindString(18, gear);
        }
        stmt.bindLong(19, entity.getSpeed());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CarRecordPointEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long recordId = entity.getRecordId();
        if (recordId != null) {
            stmt.bindLong(2, recordId);
        }
        stmt.bindDouble(3, entity.getX());
        stmt.bindDouble(4, entity.getY());
        stmt.bindDouble(5, entity.getL());
        stmt.bindDouble(6, entity.getW());
        stmt.bindDouble(7, entity.getCa());
 
        String dr = entity.getDr();
        if (dr != null) {
            stmt.bindString(8, dr);
        }
 
        String dl = entity.getDl();
        if (dl != null) {
            stmt.bindString(9, dl);
        }
 
        String fy = entity.getFy();
        if (fy != null) {
            stmt.bindString(10, fy);
        }
        stmt.bindLong(11, entity.getTime());
        stmt.bindLong(12, entity.getDg());
 
        String gradeId = entity.getGradeId();
        if (gradeId != null) {
            stmt.bindString(13, gradeId);
        }
 
        String cause = entity.getCause();
        if (cause != null) {
            stmt.bindString(14, cause);
        }
        stmt.bindLong(15, entity.getScore());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(16, name);
        }
 
        String voice = entity.getVoice();
        if (voice != null) {
            stmt.bindString(17, voice);
        }
 
        String gear = entity.getGear();
        if (gear != null) {
            stmt.bindString(18, gear);
        }
        stmt.bindLong(19, entity.getSpeed());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public CarRecordPointEntity readEntity(Cursor cursor, int offset) {
        CarRecordPointEntity entity = new CarRecordPointEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // recordId
            cursor.getFloat(offset + 2), // x
            cursor.getFloat(offset + 3), // y
            cursor.getDouble(offset + 4), // l
            cursor.getDouble(offset + 5), // w
            cursor.getFloat(offset + 6), // ca
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // dr
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // dl
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // fy
            cursor.getLong(offset + 10), // time
            cursor.getInt(offset + 11), // dg
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // gradeId
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // cause
            cursor.getInt(offset + 14), // score
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // name
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // voice
            cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // gear
            cursor.getInt(offset + 18) // speed
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CarRecordPointEntity entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setRecordId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setX(cursor.getFloat(offset + 2));
        entity.setY(cursor.getFloat(offset + 3));
        entity.setL(cursor.getDouble(offset + 4));
        entity.setW(cursor.getDouble(offset + 5));
        entity.setCa(cursor.getFloat(offset + 6));
        entity.setDr(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setDl(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setFy(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setTime(cursor.getLong(offset + 10));
        entity.setDg(cursor.getInt(offset + 11));
        entity.setGradeId(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setCause(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setScore(cursor.getInt(offset + 14));
        entity.setName(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setVoice(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setGear(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setSpeed(cursor.getInt(offset + 18));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(CarRecordPointEntity entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(CarRecordPointEntity entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(CarRecordPointEntity entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "carRecordPoint" to-many relationship of CarInfoRecordEntity. */
    public List<CarRecordPointEntity> _queryCarInfoRecordEntity_CarRecordPoint(Long recordId) {
        synchronized (this) {
            if (carInfoRecordEntity_CarRecordPointQuery == null) {
                QueryBuilder<CarRecordPointEntity> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.RecordId.eq(null));
                carInfoRecordEntity_CarRecordPointQuery = queryBuilder.build();
            }
        }
        Query<CarRecordPointEntity> query = carInfoRecordEntity_CarRecordPointQuery.forCurrentThread();
        query.setParameter(0, recordId);
        return query.list();
    }

}
